/*     */ package com.kendoui.taglib;
/*     */ 
/*     */ import com.kendoui.taglib.html.Div;
/*     */ import com.kendoui.taglib.html.Element;
/*     */ import com.kendoui.taglib.html.Script;
/*     */ import com.kendoui.taglib.json.Serializable;
/*     */ import com.kendoui.taglib.json.Serializer;
/*     */ import java.io.IOException;
/*     */ import java.io.StringWriter;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.servlet.jsp.JspException;
/*     */ import javax.servlet.jsp.JspWriter;
/*     */ import javax.servlet.jsp.PageContext;
/*     */ import javax.servlet.jsp.tagext.DynamicAttributes;
/*     */ 
/*     */ public abstract class WidgetTag extends BaseTag
/*     */   implements Serializable, DynamicAttributes
/*     */ {
/*     */   private String name;
/*     */   private String widget;
/*     */   protected Map<String, Object> attributes;
/*     */ 
/*     */   public WidgetTag(String widget)
/*     */   {
/*  27 */     this.widget = widget;
/*     */   }
/*     */ 
/*     */   public String getName() {
/*  31 */     return this.name;
/*     */   }
/*     */ 
/*     */   public void setName(String name) {
/*  35 */     this.name = name;
/*     */   }
/*     */ 
/*     */   public void initialize() {
/*  39 */     this.attributes = new HashMap();
/*     */ 
/*  41 */     super.initialize();
/*     */   }
/*     */ 
/*     */   public void destroy()
/*     */   {
/*  46 */     this.attributes = null;
/*     */ 
/*  48 */     super.destroy();
/*     */   }
/*     */ 
/*     */   public void setDynamicAttribute(String uri, String localName, Object value) throws JspException
/*     */   {
/*  53 */     this.attributes.put(localName, value);
/*     */   }
/*     */ 
/*     */   public int doEndTag() throws JspException
/*     */   {
/*  58 */     JspWriter out = this.pageContext.getOut();
/*     */ 
/*  60 */     Element element = html();
/*  61 */     Script script = script();
/*     */     try
/*     */     {
/*  64 */       element.write(out);
/*     */ 
/*  66 */       script.write(out);
/*     */     } catch (IOException exception) {
/*  68 */       throw new JspException(exception);
/*     */     }
/*     */ 
/*  71 */     return super.doEndTag();
/*     */   }
/*     */ 
/*     */   public Element<?> html() {
/*  75 */     Element element = createElement();
/*     */ 
/*  77 */     element.attr("id", getName());
/*     */ 
/*  79 */     for (String attribute : this.attributes.keySet()) {
/*  80 */       Object value = this.attributes.get(attribute);
/*     */ 
/*  82 */       if (value != null) {
/*  83 */         element.attr(attribute, value);
/*     */       }
/*     */     }
/*     */ 
/*  87 */     return element;
/*     */   }
/*     */ 
/*     */   public Script script() {
/*  91 */     StringWriter content = new StringWriter();
/*     */ 
/*  93 */     content.append("jQuery(function(){jQuery(\"#").append(getName()).append("\").kendo").append(this.widget).append("(");
/*     */     try
/*     */     {
/* 100 */       new Serializer().serialize(content, this);
/*     */     }
/*     */     catch (IOException exception)
/*     */     {
/*     */     }
/* 105 */     content.append(");})");
/*     */ 
/* 107 */     Script script = new Script();
/*     */ 
/* 109 */     script.html(content.toString());
/*     */ 
/* 111 */     return script;
/*     */   }
/*     */ 
/*     */   protected Element<?> createElement() {
/* 115 */     return new Div();
/*     */   }
/*     */ }

/* Location:           D:\Liao\kendoui.jsp.2013.1.319.trial\wrappers\jsp\kendo-taglib\kendo-taglib-2013.1.319.jar
 * Qualified Name:     com.kendoui.taglib.WidgetTag
 * JD-Core Version:    0.6.2
 */